package com.example.himalayaproject.play.playalbum.adapter;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.himalayaproject.R;
import com.example.himalayaproject.play.playalbum.bean.albumdetial.AlbumEntity;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Created by Administrator on 2016/12/12.
 */

public class PlayerAdapter extends RecyclerView.Adapter<PlayerAdapter.ViewHolder> implements View.OnClickListener {
    private Context context;
    private List<AlbumEntity> albums;
    private String playTimes;
    private String totalCount;
    private String intro;
    private String tags;

    public PlayerAdapter(Context context,String playTimes,String totalCount,String intro,String tags) {
        this.context = context;
        this.playTimes = playTimes;
        this.totalCount = totalCount;
        this.intro = intro;
        this.tags = tags;
        albums = new ArrayList<>();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(viewType,parent,false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        AlbumEntity albumEntity = albums.get(0);
        switch (position) {
            case 0:
                holder.playerName.setText(albumEntity.getNickname());
                Picasso.with(context).load(albumEntity.getSmallLogo()).into(holder.playerSrc);
                Picasso.with(context).load(albumEntity.getCoverLarge()).into(holder.albumSrc);
                holder.infoLayout.setOnClickListener(this);
                holder.albumSrc.setOnClickListener(this);
                holder.play.setOnClickListener(this);
                holder.playingList.setOnClickListener(this);
                holder.playerOff.setOnClickListener(this);
                break;
            case 1:
                holder.albumLayout.setOnClickListener(this);
                Picasso.with(context).load(albumEntity.getCoverSmall()).into((Target) holder.authorSrc);
                holder.albumName.setText(albumEntity.getAlbumTitle());
                holder.albumAuthor.setText(albumEntity.getNickname());
                holder.albumNumber.setText(playTimes);
                holder.albumEpisode.setText(totalCount+"集");
                holder.authorCollect.setOnClickListener(this);
                holder.albumInfo.setText("声音简介："+albumEntity.getTitle());
                holder.albumInfoLayout.setOnClickListener(this);
                holder.authorReward.setOnClickListener(this);
                break;
//            case 2:
//                holder.recommendAbout.setText(tags);
//                holder.recommendMore.setOnClickListener(this);
//                AlbumRecommendAdapter recommendAdapter = new AlbumRecommendAdapter(context);
//                holder.recommendRecycler.setAdapter(recommendAdapter);
//                break;
//            case 3:
//                holder.listenerComment.setText("听众点评("+albumEntity.getComments()+")");
//                holder.listenerMore.setOnClickListener(this);
//                ListenerCommentsAdapter listenerAdapter = new ListenerCommentsAdapter(context);
//                holder.listenerRecycler.setAdapter(listenerAdapter);
//
//                break;
//            case 4:
//                PlayerAlbumPagerAdapter pagerAdapter = new PlayerAlbumPagerAdapter();
//                holder.pager.setAdapter(pagerAdapter);
//                break;
        }
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return R.layout.play_item_album;
        } else if (position == 1) {
            return R.layout.play_item_author;
        }
//        else if (position == 2) {
//            return R.layout.player_recommend;
//        } else if (position == 3) {
//            return R.layout.player_listener;
//        } else if (position == 4) {
//            return R.layout.player_pager;
//        }
        return super.getItemViewType(position);
    }

    public void addAll (Collection<? extends AlbumEntity> collection) {
        int size = albums.size();
        albums.addAll(collection);
        notifyItemRangeInserted(size,collection.size());
    }

    @Override
    public int getItemCount() {
        return albums.size();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.player_album:// infoLayout
                break;
            case R.id.player_bg: //  albumSrc
                break;
            case R.id.player_play: // play
                break;
            case R.id.player_playinglist: // playingList
                break;
            case R.id.player_time_off: // playerOff
                break;
            // position =1
            case R.id.album: // albumLayout
                break;
            case R.id.player_author_collect: // authorCollect
                break;
            case R.id.layout_album_info:// albumInfoLayout
                break;
            case R.id.player_album_reward: // authorReward
                break;
//            // position =2
//            case R.id.player_recommend_more: // recommendMore
//                break;
//            // position =3
//            case R.id.player_listener_about: // listenerMore
//                break;

        }
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        private final RelativeLayout infoLayout,albumInfoLayout;
        private final RelativeLayout albumLayout;
        private ViewPager pager;
        private RecyclerView recommendRecycler,listenerRecycler;
        private TextView playerName,playingList,playerOff,recommendMore,listenerMore,albumName,albumAuthor,albumNumber,albumEpisode,albumInfo,recommendAbout,listenerComment;
        private ImageView playerSrc,playerStation,playerMore,albumSrc,previous,next,play,pause,authorCollect,authorReward;
        private CardView authorSrc;

        public ViewHolder(View itemView) {
            super(itemView);
            infoLayout = ((RelativeLayout) itemView.findViewById(R.id.player_album));
            albumLayout = ((RelativeLayout) itemView.findViewById(R.id.album));
            albumInfoLayout = ((RelativeLayout) itemView.findViewById(R.id.layout_album_info));

            playerName = ((TextView) itemView.findViewById(R.id.player_album_name));
            playingList = ((TextView) itemView.findViewById(R.id.player_playinglist));
            playerOff = ((TextView) itemView.findViewById(R.id.player_time_off));
            recommendMore = ((TextView) itemView.findViewById(R.id.player_recommend_more));
            listenerMore = ((TextView) itemView.findViewById(R.id.player_listener_about));
            albumName = ((TextView) itemView.findViewById(R.id.player_album));
            albumAuthor = ((TextView) itemView.findViewById(R.id.player_album_author));
            albumNumber = ((TextView) itemView.findViewById(R.id.player_album_number));
            albumEpisode = ((TextView) itemView.findViewById(R.id.player_album_episode));
            albumInfo = ((TextView) itemView.findViewById(R.id.player_album_info));
            recommendAbout = ((TextView) itemView.findViewById(R.id.player_recommend_about));
            listenerComment = ((TextView) itemView.findViewById(R.id.player_listener_comment));

            playerSrc = (ImageView) itemView.findViewById(R.id.player_album_src);
            playerStation = (ImageView) itemView.findViewById(R.id.player_station);
            playerMore = (ImageView) itemView.findViewById(R.id.player_album_more);
            albumSrc = (ImageView) itemView.findViewById(R.id.player_bg);
//            previous = (ImageView) itemView.findViewById(R.id.player_previous);
//            next = (ImageView) itemView.findViewById(R.id.player_next);
            play = (ImageView) itemView.findViewById(R.id.player_play);
            pause = (ImageView) itemView.findViewById(R.id.player_pause);
            authorCollect = (ImageView) itemView.findViewById(R.id.player_author_collect);
            authorReward = (ImageView) itemView.findViewById(R.id.player_album_reward);
            authorSrc = (CardView) itemView.findViewById(R.id.player_author_src);

            recommendRecycler = ((RecyclerView) itemView.findViewById(R.id.player_recommend));
            listenerRecycler = ((RecyclerView) itemView.findViewById(R.id.player_listener));



            pager = ((ViewPager) itemView.findViewById(R.id.player_pager));
        }
    }
}
